<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('components', function (Blueprint $table) {
            $table->id();
            $table->foreignId('admin_id')->default(1)->constrained();
            $table->string('title');
            $table->string('chinese_title')->nullable();
            $table->string('japanese_title')->nullable();
            $table->string('slug')->unique();
            $table->string('description')->nullable()->comment("this is a markdown content");
            $table->string('description_html')->nullable()->comment('description转成HTML');
            $table->tinyInteger('count')->default(0)->comment('included component count');
            $table->json('viewports')->default(json_encode(["mobile", "tablet", "desktop"]))->comment('排在第一个的是默认的');
            $table->text('demo_data')->nullable()->comment('demo data to show for the component');
            $table->text('component_tree')->nullable()->comment('showing structure of the components in a form json');
            $table->json('related')->nullable();
            $table->string('screenshot')->default('images/component-default.png');
            $table->tinyInteger('vip_level')->default(0);
            $table->boolean('is_visible')->default(true);
            $table->json('related_tutorial')->nullable();
            $table->string('download_path');
            $table->json('tags')->nullable();
            $table->timestamps();
        });

        DB::table('components')->insert([
             [
                 'admin_id' => 1,
                 'title' => 'Button',
                 'chinese_title' => '按钮',
                 'slug' => 'button',
                 'download_path' => 'form/buttons',
                 'description' => 'this is a button component',
                 'screenshot' => '01JY61AW23GCGD8R3AFS4YWJSD.webp',
             ],
            [
                'admin_id' => 1,
                'title' => 'Button2',
                'chinese_title' => '按钮2',
                'slug' => 'button2',
                'download_path' => 'form/buttons',
                'description' => 'this is a button 2 component',
                'screenshot' => '01JY61AW23GCGD8R3AFS4YWJSD.webp',
            ],
            [
                'admin_id' => 1,
                'title' => 'Button3',
                'chinese_title' => '按钮3',
                'download_path' => 'form/buttons',
                'slug' => 'button3',
                'description' => 'this is a button 3 component',
                'screenshot' => '01JY61AW23GCGD8R3AFS4YWJSD.webp',
            ],
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('components');
    }
};
